package com.zh.note.huawei.onehundred.有效子字符串;

import java.util.Scanner;

/**
 * @Author: zhanghuan
 * @date: 2023/9/3 10:28
 * @description: create it
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String l = sc.nextLine();
        char[] chars = s.toCharArray();
        int index = -1;
        for (int i = 0; i < chars.length; i++) {
            index = l.indexOf(chars[i], index + 1);
            if (index == -1) {
                System.out.println(-1);
                return;
            }
            if (i == chars.length - 1) {
                System.out.println(index);
            }

        }
    }
}
